﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Abs.Core;
namespace Abs.App.Admin
{
    public partial class Edit_User : System.Web.UI.Page
    {

        private Abs.Core.Models.User.User user;
        private Abs.Core.Management.UserManagement userManagement;
        protected void Page_Load(object sender, EventArgs e)
        {
            //Kicks the non admin accounts out
            if (Session["Role"] == null)
                Response.Redirect("~/User/Unauthorized_Access.aspx");
            if ((int)Session["Role"] == (int)Abs.Core.Models.User.RoleEnum.User)
                Response.Redirect("~/User/Unauthorized_Access.aspx");

            userManagement = Abs.Core.Management.Manage.User;

            user = userManagement.Select(Request.QueryString["Email"]);

            if (user == null)
            {
                Response.Redirect("~/Default.aspx");
            }

            Text_Email.Text = user.Email;
            Text_Name0.Text = user.Name;

            
        }

        protected void Submit_Click(object sender, EventArgs e)
        {
            if (userManagement.Update(user.Email, Text_Name.Text, (int)Abs.Core.Models.User.RoleEnum.User))
            {
                Response.Redirect("~/Admin/Manage_Users.aspx");
            }
            Response.Redirect("~/Default.aspx");
        }
    }
}